﻿using System;
using System.Collections.Generic;

namespace YJKBatchPrinter
{
	public class GBPaperSize
	{
		public static GBPaperSize Instance()
		{
			return new GBPaperSize();
		}

		public bool getPSizeByName(string sName, ref pSize ps)
		{
			bool result = false;
			if (!string.IsNullOrEmpty(sName))
			{
				foreach (KeyValuePair<string, pSize> keyValuePair in this.m_dicGBPSize)
				{
					if (keyValuePair.Key.Equals(sName))
					{
						ps = keyValuePair.Value;
						break;
					}
				}
			}
			return result;
		}

		public string getSelfPaperSizeName(string sPrinterName, double viewH, double viewW, bool bIsLandScope)
		{
			string text = "";
			SortedDictionary<double, string> sortedDictionary = new SortedDictionary<double, string>();
			foreach (KeyValuePair<string, pSize> keyValuePair in this.m_dicGBPSize)
			{
				double num;
				if (bIsLandScope)
				{
					num = viewH - (double)keyValuePair.Value.m_Width;
				}
				else
				{
					num = viewW - (double)keyValuePair.Value.m_Width;
				}
				num = Math.Abs(num);
				if (!sortedDictionary.ContainsKey(num))
				{
					sortedDictionary.Add(num, keyValuePair.Key);
				}
			}
			using (SortedDictionary<double, string>.Enumerator enumerator2 = sortedDictionary.GetEnumerator())
			{
				if (enumerator2.MoveNext())
				{
					KeyValuePair<double, string> keyValuePair2 = enumerator2.Current;
					text = keyValuePair2.Value;
				}
			}
			sortedDictionary.Clear();
			foreach (KeyValuePair<string, pSize> keyValuePair3 in this.m_dicGBPSize)
			{
				if (keyValuePair3.Key.Contains(text))
				{
					double num2;
					if (bIsLandScope)
					{
						num2 = viewW - (double)keyValuePair3.Value.m_Height;
					}
					else
					{
						num2 = viewH - (double)keyValuePair3.Value.m_Height;
					}
					num2 = Math.Abs(num2);
					if (!sortedDictionary.ContainsKey(num2))
					{
						sortedDictionary.Add(num2, keyValuePair3.Key);
					}
				}
			}
			using (SortedDictionary<double, string>.Enumerator enumerator2 = sortedDictionary.GetEnumerator())
			{
				if (enumerator2.MoveNext())
				{
					KeyValuePair<double, string> keyValuePair4 = enumerator2.Current;
					text = keyValuePair4.Value;
				}
			}
			return text;
		}

		private void insertPSize(string sName, float dW, float dH)
		{
			float num = 30f;
			if (!string.IsNullOrEmpty(sName))
			{
				pSize value = new pSize(dW + num, dH + num);
				this.m_dicGBPSize.Add(sName, value);
			}
		}

		private float CalcSizeH(float dH, float dParam)
		{
			return dH + dH * dParam;
		}

		private void addA0Size()
		{
			float dW = 841f;
			float num = 1189f;
			float dH = num;
			string sName = "HYA0";
			this.insertPSize(sName, dW, dH);
			dH = this.CalcSizeH(num, 0.25f);
			sName = "HYA0+1/4";
			this.insertPSize(sName, dW, dH);
			dH = this.CalcSizeH(num, 0.5f);
			sName = "HYA0+1/2";
			this.insertPSize(sName, dW, dH);
			dH = this.CalcSizeH(num, 0.75f);
			sName = "HYA0+3/4";
			this.insertPSize(sName, dW, dH);
			dH = this.CalcSizeH(num, 1f);
			sName = "HYA0+1";
			this.insertPSize(sName, dW, dH);
			dH = this.CalcSizeH(num, 1.25f);
			sName = "HYA0+5/4";
			this.insertPSize(sName, dW, dH);
		}

		private void addA1Size()
		{
			float dW = 594f;
			float num = 841f;
			float dH = num;
			string sName = "HYA1";
			this.insertPSize(sName, dW, dH);
			dH = this.CalcSizeH(num, 0.25f);
			sName = "HYA1+1/4";
			this.insertPSize(sName, dW, dH);
			dH = this.CalcSizeH(num, 0.5f);
			sName = "HYA1+1/2";
			this.insertPSize(sName, dW, dH);
			dH = this.CalcSizeH(num, 0.75f);
			sName = "HYA1+3/4";
			this.insertPSize(sName, dW, dH);
			dH = this.CalcSizeH(num, 1f);
			sName = "HYA1+1";
			this.insertPSize(sName, dW, dH);
			dH = this.CalcSizeH(num, 1.25f);
			sName = "HYA1+5/4";
			this.insertPSize(sName, dW, dH);
		}

		private void addA2Size()
		{
			float dW = 420f;
			float num = 594f;
			float dH = num;
			string sName = "HYA2";
			this.insertPSize(sName, dW, dH);
			dH = this.CalcSizeH(num, 0.25f);
			sName = "HYA2+1/4";
			this.insertPSize(sName, dW, dH);
			dH = this.CalcSizeH(num, 0.5f);
			sName = "HYA2+1/2";
			this.insertPSize(sName, dW, dH);
			dH = this.CalcSizeH(num, 0.75f);
			sName = "HYA2+3/4";
			this.insertPSize(sName, dW, dH);
			dH = this.CalcSizeH(num, 1f);
			sName = "HYA2+1";
			this.insertPSize(sName, dW, dH);
			dH = this.CalcSizeH(num, 1.25f);
			sName = "HYA2+5/4";
			this.insertPSize(sName, dW, dH);
		}

		private void addA3Size()
		{
			float dW = 297f;
			float num = 420f;
			float dH = num;
			string sName = "HYA3";
			this.insertPSize(sName, dW, dH);
			dH = this.CalcSizeH(num, 0.25f);
			sName = "HYA3+1/4";
			this.insertPSize(sName, dW, dH);
			dH = this.CalcSizeH(num, 0.5f);
			sName = "HYA3+1/2";
			this.insertPSize(sName, dW, dH);
			dH = this.CalcSizeH(num, 0.75f);
			sName = "HYA3+3/4";
			this.insertPSize(sName, dW, dH);
			dH = this.CalcSizeH(num, 1f);
			sName = "HYA3+1";
			this.insertPSize(sName, dW, dH);
			dH = this.CalcSizeH(num, 1.25f);
			sName = "HYA3+5/4";
			this.insertPSize(sName, dW, dH);
		}

		private void addA4Size()
		{
			float dW = 210f;
			float dH = 297f;
			string sName = "HYA4";
			this.insertPSize(sName, dW, dH);
		}

		private GBPaperSize()
		{
			this.m_dicGBPSize = new Dictionary<string, pSize>();
			this.addA0Size();
			this.addA1Size();
			this.addA2Size();
			this.addA3Size();
			this.addA4Size();
		}

		public Dictionary<string, pSize> m_dicGBPSize;
	}
}
